import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(12, 8))


def areaView(df):
	counts = df.groupby(by="地址").count()
	plt.title("各个地区车辆数量分析")
	# 设置x轴标签
	x = range(len(counts.index))
	plt.ylabel("数量")
	plt.bar(counts.index, counts["会员"], label="数量")
	plt.xticks(x, counts.index)
	plt.legend()
	plt.show()


def distanceView(df):
	# 分割数据为不同的区间
	divide = [0, 2, 4, 8, 10, 50, 1000]
	# 获取列数据
	cut = pd.cut(list(df["里程"]), divide)
	data = cut.describe()
	# 绘制扇形图
	plt.pie(x=data.freqs, labels=data.index, autopct="%1.2f%%", pctdistance=0.9, explode=(0, 0, 0, 0, 0.4, 0.2))
	plt.legend(loc='upper left')
	plt.title("里程占比分析（万里）")
	plt.show()


def timeView(df):
	plt.figure(figsize=(22, 8))
	counts = df.groupby(by="时间").count()  # 统计
	plt.title("各年份二手车数量")
	plt.plot(counts.index, counts["名称"], label="数量")
	plt.xticks(counts.index)
	plt.ylabel("数量")
	plt.show()


def priceView(df):
	# 分割数据为不同的区间
	divide = [0, 10, 20, 30, 50, 100, 500, 10000]
	# 获取价格列数据
	cut = pd.cut(list(df["价格"]), divide)
	data = cut.describe()
	# 绘制扇形图
	plt.pie(x=data.freqs, labels=data.index, autopct="%1.2f%%", explode=(0, 0, 0, 0, 0, 0.2, 0.4))
	plt.legend(loc='upper left')
	plt.title("车辆价格占比分析（万元）")
	plt.show()

